﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace CPETwit.Web.Converter
{
    public class TimeConverter
    {
        public object Convert(object value)
        {
            if (value is DateTime)
            {
                DateTime? dateTime = value as DateTime?;
                double seconds = DateTime.Now.Subtract(dateTime.Value).TotalSeconds;
                TimeSpan dt = TimeSpan.FromSeconds(seconds);

                //if (dt.Year != 0)
                //    return dt.Year + " an" + (dt.Year > 0 ? " s" : string.Empty);
                //if (dt.Month != 0)
                //    return dt.Month + " mois";
                if (dt.Days != 0)
                    return dt.Days + " jour" + (dt.Days > 1 ? "s" : string.Empty);
                if (dt.Hours != 0)
                    return dt.Hours + " heure" + (dt.Hours > 1 ? "s" : string.Empty);
                if (dt.Minutes != 0)
                    return dt.Minutes + " min";
                if (dt.Seconds != 0)
                    return dt.Seconds + " s";
            }
            return string.Empty;
        }
    }
}